﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Seagull.Configuration;
using Seagull.Model;

namespace Seagull.Shell.Utils
{
    static class FrameDataWarningHelper
    {
        public static int GetWarningLevel(Frame frame)
        {
            var channel = frame.Channel;
            if(!Config.Instance.ChannelConfig.HasChannel(channel))
            {
                return 0;
            }

            int level;
            var warningQuota1 = Config.Instance.ChannelConfig[channel].WarningQuota1;
            var warningQuota2 = Config.Instance.ChannelConfig[channel].WarningQuota2;
            var quotaWarningMinCount = Config.Instance.DataReadConfig.QuotaWarningMinCount;
            if(warningQuota2 > 0 && frame.Data.Count(t => t > warningQuota2) > quotaWarningMinCount)
            {
                level = 2;
            }
            else if(warningQuota1 > 0 && frame.Data.Count(t => t > warningQuota1) > quotaWarningMinCount)
            {
                level = 1;
            }
            else
            {
                level = 0;
            }
            return level;
        }
    }
}
